package com.qk.ezbuy.controller;

import com.github.pagehelper.PageInfo;
import com.qk.ezbuy.pojo.Order;
import com.qk.ezbuy.pojo.OrderDetail;
import com.qk.ezbuy.pojo.User;
import com.qk.ezbuy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Order")
public class OrderController {
    @Autowired
    private OrderService orderService;



    @RequestMapping("OrderAll")
    public Map OrderAll(@RequestParam int pageNum, @RequestParam int pageSize, int id){
        PageInfo<Order> pageInfo=null;
        pageInfo=orderService.selectUserById(pageNum,pageSize,id);
        PageInfo<Order> orderList = orderService.selectUserById(pageNum,pageSize,id);
        Map<String,Object> map = new HashMap<>();
        List<Order> ordersList = orderService.selectProduct();
        map.put("ordersList",ordersList);
        map.put("pageInfo",pageInfo);
        return map;
    }

    @GetMapping("OrderselectPage")
    public Map selectByPage(@RequestParam int pageNum, @RequestParam int pageSize){
        PageInfo<Order> pageInfo=null;
        pageInfo=orderService.selectPage(pageNum,pageSize);
        Map<String,Object> map = new HashMap<>();
        pageInfo.setPageNum(pageNum);
        map.put("pageInfo",pageInfo);

        List<Order> ordersList = orderService.selectProduct();
        map.put("ordersList",ordersList);
        return map;
    }

    @RequestMapping("delOrderById")
    public Map delOrderById(Order order){
        Map<String,Object> map = new HashMap<>();
        order.setIsno(1);
        int count = orderService.delOrderById(order);
        if(count>0){
            map.put("msg",1);
        }else{
            map.put("msg",2);
        }
        return map;
    }

}
